//
//  CollectSegmentViewController.m
//  BaseProject
//
//  Created by 王洋 on 2020/7/28.
//  Copyright © 2020 王洋. All rights reserved.
//
#import "XLPageViewController.h"

#import "ProductCollectViewController.h"
#import "PackageCollectViewController.h"
#import "StoreCollectViewController.h"
#import "CaseCollectViewController.h"


#import "CollectSegmentViewController.h"

@interface CollectSegmentViewController ()<XLPageViewControllerDelegate,XLPageViewControllerDataSrouce>

@property (nonatomic, strong) XLPageViewController *pageViewController;

@end

@implementation CollectSegmentViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    [self initView];
}

- (void)initView {

    self.title = @"收藏";
    self.view.backgroundColor = UIColorHex(0xffffff);

    [self initPageViewController];
}

- (void)goBack {
    
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)initPageViewController {
    
    XLPageViewControllerConfig *config = [XLPageViewControllerConfig defaultConfig];
    config.shadowLineColor = UIColorHex(0xff4242);
    config.titleSelectedFont = [UIFont boldSystemFontOfSize:14];
    config.titleNormalFont = [UIFont systemFontOfSize:14];
    config.titleViewAlignment = XLPageTitleViewAlignmentCenter;
    config.separatorLineHidden = true;
    config.shadowLineAnimationType = XLPageShadowLineAnimationTypeZoom;
    config.shadowLineWidth = 20;
    config.titleSpace = 0;
    config.titleWidth = TTScreenWidth/5;
    
    self.pageViewController = [[XLPageViewController alloc] initWithConfig:config];
    self.pageViewController.view.frame = self.view.bounds;
    self.pageViewController.delegate = self;
    self.pageViewController.dataSource = self;
    [self addChildViewController:self.pageViewController];
    [self.view addSubview:self.pageViewController.view];
}

#pragma mark -
#pragma mark TableViewDelegate&DataSource
- (UIViewController *)pageViewController:(XLPageViewController *)pageViewController viewControllerForIndex:(NSInteger)index {

    switch (index) {
        case 0:{
            PackageCollectViewController *vc = [[PackageCollectViewController alloc] init];
            return vc;
        } break;
        case 1:{
            StoreCollectViewController *vc = [[StoreCollectViewController alloc] init];
            return vc;
        } break;
        case 2:{
            CaseCollectViewController *vc = [[CaseCollectViewController alloc] init];
            return vc;
        } break;
        case 3:{
            ProductCollectViewController *vc = [[ProductCollectViewController alloc] init];
            return vc;
        } break;
            
        default:
            break;
    }
    return [UIViewController new];
}

- (NSString *)pageViewController:(XLPageViewController *)pageViewController titleForIndex:(NSInteger)index {
    return [self titles][index];
}

- (NSInteger)pageViewControllerNumberOfPage {
    return [self titles].count;
}

- (void)pageViewController:(XLPageViewController *)pageViewController didSelectedAtIndex:(NSInteger)index {
    NSLog(@"切换到了：%@",[self titles][index]);
}

#pragma mark -
#pragma mark 标题数据
- (NSArray *)titles {
    return @[@"套餐",@"商家",@"案例",@"婚品"];
}

@end
